<script>
import BaseUrl from "@/http/request/BaseUrl";
import TokenAxios from "@/http/request/TokenAxios";

export default {
  data(){
    return{
      // 当前每页显示多少条数据
      pageSize: 10,
      //分页相关数据
      currentPage: this.$router.currentRoute.query.page ? parseInt(this.$router.currentRoute.query.page) : 1,
      tableData: [],
      total: 0,
    }
  },
  methods:{
// 切换分页
    handleCurrentChange(page) {
      // 修改当前页码时，使用 $router.push 而不是 $router.replace，保留浏览器的历史记录
      this.$router.replace('?page=' + page);
      this.loadUserList(page); // 将当前页码传递给 loadUserList 方法
    },
    loadUserList() {
      console.log('开始加载用户列表');
      let page = this.$router.currentRoute.query.page;
      console.log('开始加载用户列表，页码为', page);
      if (!page) {
        page = 1;
      }
      let url = BaseUrl.ADMIN_COMPLAINT + '/admin/complaint/log/list?pageNum=' + page+'&pageSize='+this.pageSize;

      TokenAxios.get(url,page).then((response) => {
        console.log('当前页码：', this.currentPage);
        console.log('每页显示条数：', this.pageSize);
        console.log('请求 URL：', url);
        let jsonResult = response.data;
        if (jsonResult.state == 20000) {
          this.tableData = jsonResult.data.list;
          this.tableData.forEach((item)=>{
            if(item.result==0){
              item.result = {
                text:"举报无效",
                type: 'success'
              }
            }else if(item.result==1){
              item.result = {
                text: "删除内容",
                type: 'warning'
              }
            }else if(item.result==2){
              item.result = {
                text: "封禁用户",
                type: 'danger'
              }
            }else {
              let title = '操作失败';
              this.$alert(jsonResult.message, title, {
                confirmButtonText: '确定',
                callback: action => {
                }
              })
            }
          })
          this.currentPage = jsonResult.data.currentPage;
          this.pageSize = jsonResult.data.pageSize;
          this.total = jsonResult.data.total;
          console.log('用户列表数据：', this.tableData);
          console.log('当前页码：', this.currentPage);
          console.log('每页显示条数：', this.pageSize);
          console.log('总条数：', this.total);
        } else {
          let title = '操作失败';
          this.$alert(jsonResult.message, title, {
            confirmButtonText: '确定',
            callback: action => {
            }
          })
        }
      })
    }
  },
  mounted(){
    let page = this.$route.query.page; // 通过 $route 获取当前页码
    this.loadUserList(page); // 将当前页码传递给 loadUserList 方法
  },
}
</script>


<template>
  <div>
    <!--面包屑导航区域-->
    <el-breadcrumb separator-class="el-icon-arrow-right" style="margin-bottom: 20px;overflow: hidden">
      <el-breadcrumb-item :to="{ path: '/admin/index' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>投诉列表</el-breadcrumb-item>
    </el-breadcrumb>


    <el-card>
      <el-table :data="tableData"
                border stripe
                style="margin-bottom: 20px;overflow: hidden">
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column
            prop="id"
            label="ID"
        >
        </el-table-column>
        <el-table-column
            prop="username"
            label="处理人"
        >
        </el-table-column>
        <el-table-column
            prop="complaintNumber"
            label="投诉单号"
            :show-overflow-tooltip="true"
        ></el-table-column>

        <el-table-column
            prop="result"
            label="处理结果"
        >
          <template slot-scope="scope">
            <el-tag :type="scope.row.result.type">{{ scope.row.result.text }}</el-tag>
          </template>
        </el-table-column>

        <el-table-column
            prop="createTime"
            label="创建时间"
        >
        </el-table-column>
        <el-table-column
            prop="updateTime"
            label="修改时间"
        >
        </el-table-column>
      </el-table>
      <!--分页区域-->
      <el-pagination
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :hide-on-single-page="true"
          :page-size="pageSize"
          layout="total, prev, pager, next,jumper"
          :total="total"
          background
      >
      </el-pagination>

    </el-card>
  </div>
</template>


<style scoped>

</style>